package com.zhongde.cloud89app.adapter;

import android.content.Context;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zhongde.cloud89app.R;
import com.zhongde.cloud89app.activity.RegActivity;
import com.zhongde.cloud89app.bean.Equipment;
import com.zhongde.cloud89app.utils.MyPreference;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;


public class EquipmentsAdapter extends BaseQuickAdapter<Equipment, BaseViewHolder> {

    private MyPreference pref;
    private int key = 0;


    public EquipmentsAdapter(int layoutResId, @Nullable List<Equipment> data, Context context) {
        super(layoutResId, data);
        pref = new MyPreference(context);
        key = pref.getInt("userleve");
    }


    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, Equipment equipment) {
        baseViewHolder.setText(R.id.ename, equipment.getEquipmentId());
        baseViewHolder.setText(R.id.areaname, equipment.getAreaName());
        baseViewHolder.setText(R.id.item_wheel_All, "总轮数：" + equipment.getWheelAll());
        baseViewHolder.setText(R.id.item_area_number, "总表数：" + equipment.getAreaNumber());

        if (key == 2) {
            baseViewHolder.setVisible(R.id.btn_view, false);
            baseViewHolder.setVisible(R.id.item_settings_equipment, false);
        } else {
            baseViewHolder.setVisible(R.id.btn_view, true);
            baseViewHolder.setVisible(R.id.item_settings_equipment, true);
        }

        switch (equipment.getCondit()) {
            case 0:
                baseViewHolder.setText(R.id.item_condit, "(未连接)");
                break;
            case 1:
                baseViewHolder.setText(R.id.item_condit, "(已连接)");
                break;
            default:
                baseViewHolder.setText(R.id.item_condit, "(未知)");
                break;
        }

        switch (equipment.getTask_status()) {
            case 0:
                baseViewHolder.setText(R.id.item_task_status, "待机中");
                break;
            case 1:
                baseViewHolder.setText(R.id.item_task_status, "抄表中");
                break;
            case 2:
                baseViewHolder.setText(R.id.item_task_status, "禁抄时间段中");
                break;
            case 3:
                baseViewHolder.setText(R.id.item_task_status, "手动暂停中");
                break;
            default:
                baseViewHolder.setText(R.id.item_condit, "未知");
                break;
        }
    }
}
